<template>
  <div class="app-container">
    <el-form :model="queryParams2" ref="queryForm2" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="表名" prop="tableName">
        <el-input disabled="true" style="width: 300px"
                  v-model="queryParams2.tableName"
                  placeholder="请输入表名"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="中文名称" prop="tableChineseName">
        <el-input disabled="true"  style="width: 300px"
                  v-model="queryParams2.tableChineseName"
                  placeholder="请输入中文名称"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="hisVersionVal" label="版本号" prop="hisVersionVal">
        <el-input disabled="true"  style="width: 300px"
                  v-model="queryParams2.hisVersionVal"
                  placeholder="请输入版本号"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
    </el-form>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">

      <el-form-item  label="所属模块" prop="strModular">
        <treeselect style="width: 300px;" v-model="queryParams.strModular" :show-count="true"
                    :multiple="true"
                    :disable-branch-nodes="true"
                    @keyup.enter.native="handleQuery"
                    :options="modularTree"  placeholder="请选择所属模块" />
      </el-form-item>
      <el-form-item  label="所属报表" prop="strReport">
        <treeselect style="width: 300px;" v-model="queryParams.strReport" :show-count="true"
                    :multiple="true"
                    :disable-branch-nodes="true"
                    @keyup.enter.native="handleQuery"
                    :options="reportTree"  placeholder="请选择所属报表" />
      </el-form-item>
      <el-form-item  label="所属客户" prop="strCustomer">
        <treeselect style="width: 300px;" v-model="queryParams.strCustomer" :show-count="true"
                    :multiple="true"
                    :disable-branch-nodes="true"
                    @keyup.enter.native="handleQuery"
                    :options="customerTree"  placeholder="请选择所属客户" />
      </el-form-item>
      <el-form-item label="字段名称" prop="columnName" >
        <el-input
          v-model="queryParams.columnName"
          placeholder="请输入字段名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="字段中文名称"  prop="columnChineseName" v-show="showSearchColl">
        <el-input
          v-model="queryParams.columnChineseName"
          placeholder="请输入字段中文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否业务主键" prop="businessPrimaryKey" v-show="showSearchColl">
        <el-select filterable v-model="queryParams.businessPrimaryKey" placeholder="请选择是否业务主键" clearable>
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否技术主键" prop="primaryKey" v-show="showSearchColl">
        <el-select v-model="queryParams.primaryKey" placeholder="请选择是否技术主键" clearable>
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否可为空" prop="columnNull" v-show="showSearchColl">
        <el-select filterable v-model="queryParams.columnNull" placeholder="请选择是否可为空" clearable>
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="字段类型" prop="columnType" v-show="showSearchColl">
        <el-select filterable v-model="queryParams.columnType" placeholder="请选择字段类型" clearable>
          <el-option
            v-for="dict in dict.type.column_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="版本号" prop="version" v-show="showSearchColl">
        <el-select v-model="queryParams.version" placeholder="请选择版本号" clearable>
          <el-option
            v-for="dict in dict.type.report_version"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status" v-show="showSearchColl">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_common_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['reportworld:detail:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['reportworld:detail:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-edit-outline"
          size="mini"
          @click="handleUpdateOrderNum"
          v-hasPermi="['reportworld:detail:orderNum']"
        >保存顺序</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['reportworld:detail:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleCopy"
          v-hasPermi="['reportworld:detail:copy']"
        >复制</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['reportworld:detail:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleUpdateBatch"
          v-hasPermi="['reportworld:detail:batchEdit']"
        >批量修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-close"
          size="mini"
          @click="handleClose"
        >关闭</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" :showSearchColl.sync="showSearchColl" :searchColl="searchColl" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" max-height="550px"
              :data="detailList"
              row-key="id"
              border="border"
              @selection-change="handleSelectionChange"
              @sort-change="handleSortChange"
              :row-style="tableRowStyle" @row-click="rowClick"  ref="tableDetail">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column  type="index" min-width="5%"  label="编号"> </el-table-column>
      <el-table-column
        v-hasPermi="['reportworld:detail:query','reportworld:detail:demandBug','reportworld:detail:data:comparedata']"
        label="操作" align="center" width="200" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdate(scope.row,false)"
            v-hasPermi="['reportworld:detail:query']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="detailDemandBug(scope.row)"
            v-hasPermi="['reportworld:detail:demandBug']"
          >修改记录</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="comparedata(scope.row)"
            v-hasPermi="['reportworld:detail:data:comparedata']"
          >历史记录</el-button>
        <!--  <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)" v-hasPermi="['reportworld:detail:data:comparedata']">
            <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item  command="comparedata" icon="el-icon-edit"
                                 v-hasPermi="['reportworld:detail:data:comparedata']">历史记录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>-->
        </template>
      </el-table-column>
      <el-table-column label="表主键" align="center" v-if="false" prop="tableId" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="字段名称" align="center" width="150" prop="columnName" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="字段中文名称" align="center"  width="150" prop="columnChineseName" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="字段类型"  width="150" align="center" prop="columnType" sortable="custom" :sort-orders="['descending', 'ascending']">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.column_type" :value="scope.row.columnType"/>
        </template>
      </el-table-column>
      <el-table-column label="字段长度" align="center" width="100" prop="columnLength" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="小数位数" align="center" width="100" prop="columnDecimal" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="字典编码" align="center" width="100" prop="codeName"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['descending', 'ascending']"
                       >
      <template slot-scope="scope">
        <a @click="handleDataDictDetail(scope.row)" style="color:blue;cursor:pointer;font-size: 12px;">{{scope.row.codeName}}</a>
      </template>
      </el-table-column>
      <el-table-column label="所属模块" width="150" align="center" prop="strModularName" :show-overflow-tooltip="true" />
      <el-table-column label="所属报表" width="150" align="center" prop="strReportName" :show-overflow-tooltip="true" />
      <el-table-column label="所属客户" width="150" align="center" prop="strCustomerName" :show-overflow-tooltip="true" />
      <el-table-column label="是否可为空" width="100" align="center" prop="columnNull">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.columnNull"/>
        </template>
      </el-table-column>
      <el-table-column label="默认值" align="center" width="100" prop="columnDefault" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="来源的字段" align="center" width="120" prop="originalColumnName" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="是否主键" align="center" prop="primaryKey">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.primaryKey"/>
        </template>
      </el-table-column>
      <el-table-column label="是否业务主键" align="center" width="100" prop="businessPrimaryKey">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.businessPrimaryKey"/>
        </template>
      </el-table-column>
      <el-table-column label="外键对应的表名" align="center" width="150" prop="foreignTable" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="外键对应表字段" align="center" width="150" prop="foreignTableColumn" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="版本号" align="center" width="150" prop="version" sortable="custom" :sort-orders="['descending', 'ascending']">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.report_version" :value="scope.row.version"/>
        </template>
      </el-table-column>
      <el-table-column label="字段顺序" align="center" width="100" prop="orderNum" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="内容是否中文" align="center" width="130" prop="matcherChineseContent">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.matcherChineseContent"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="添加时间" align="center" prop="createTime" width="180" sortable="custom" :sort-orders="['descending', 'ascending']">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="添加人" align="center" width="150" prop="createBy" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="编辑时间" align="center" prop="updateTime" width="180" sortable="custom" :sort-orders="['descending', 'ascending']">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="编辑人" align="center" width="150" prop="updateBy" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
    </el-table>

    <!-- 添加或修改报标世界明细信息对话框 -->
    <el-dialog :title="title" :close-on-click-modal ="false" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-input clearable v-model="form.tableId" v-if="false" placeholder="请输入字段名称"/>
        <el-row>
          <el-col :span="24">
            <el-form-item label="字段名称" maxlength="30" prop="columnName">
              <el-input clearable v-model="form.columnName" placeholder="请输入字段名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="字段中文名称" maxlength="200" prop="columnChineseName">
              <el-input clearable v-model="form.columnChineseName" placeholder="请输入字段中文名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="字段类型" prop="columnType">
              <el-select @change="changeType($event)" clearable v-model="form.columnType" placeholder="请选择字段类型">
                <el-option
                  v-for="dict in dict.type.column_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="字段长度" prop="columnLength"
                          v-if="(this.batchEdit == true || (form.columnType === 1 ||form.columnType === 2||form.columnType === 3 ||form.columnType === 5  ||form.columnType === 9 ||form.columnType === 10)) ? true:false"
                          :rules="(this.batchEdit == false && (form.columnType === 1 ||form.columnType === 2||form.columnType === 3 ||form.columnType === 5  || form.columnType === 9 ||form.columnType === 10)) ? [{ required: true, message: '字段长度不能为空'}]:rules.target">
              <el-input-number style="width: 220px" placeholder="请输入字段长度" v-model="form.columnLength" controls-position="right" :min="this.batchEdit == false ?1:''"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="小数位数" prop="columnDecimal"
                          v-if="(this.batchEdit == true || form.columnType === 3) ? true:false"
                          :rules="(this.batchEdit == false && form.columnType === 3) ? [{ required: true, message: '小数位数不能为空'}]:rules.target">
              <el-input-number clearable style="220px" placeholder="请输入小数位数"  v-model="form.columnDecimal" controls-position="right" :min="this.batchEdit == false ? 0:''"/>
            </el-form-item>
          </el-col>
            <el-col v-if="batchEdit== true" :span="12">
              <el-form-item label="是否主键" prop="primaryKey">
                <el-select clearable v-model="form.primaryKey" placeholder="请选择是否主键">
                  <el-option
                    v-for="dict in dict.type.sys_yes_no"
                    :key="dict.value"
                    :label="dict.label"
                    :value="parseInt(dict.value)"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          <el-col  v-if="batchEdit== false" :span="12">
            <el-form-item label="是否主键" prop="primaryKey">
              <el-radio-group v-model="form.primaryKey">
                <el-radio
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col v-if="batchEdit== true" :span="12">
            <el-form-item label="是否可为空" prop="columnNull">
              <el-select clearable v-model="form.columnNull" placeholder="请选择是否可为空">
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col v-if="batchEdit== false" :span="12">
            <el-form-item label="是否可为空" prop="columnNull">
              <el-radio-group v-model="form.columnNull">
                <el-radio
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item  label="所属模块" prop="strModular">
              <treeselect style="width: 600px;" v-model="form.strModular"
                          :show-count="true"
                          :multiple="true"
                          :disable-branch-nodes="true"
                          :options="modularTree"
                           placeholder="请选择所属模块"/>
            </el-form-item>
          </el-col>
          <el-col v-if="batchEdit== true" :span="12">
            <el-form-item label="清空所属模块" prop="clearModular">
              <el-switch v-model="form.clearModular"></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="所属客户" prop="strCustomer">
              <treeselect style="width: 600px;" v-model="form.strCustomer"
                          :show-count="true"
                          :multiple="true"
                          :disable-branch-nodes="true"
                          :options="customerTree"
                           placeholder="请选择所属客户"/>
            </el-form-item>
          </el-col>
          <el-col v-if="batchEdit== true" :span="12">
            <el-form-item label="清空所属客户" prop="clearCustomer">
              <el-switch v-model="form.clearCustomer"></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="所属报表" prop="strReport">
              <treeselect style="width: 600px;" v-model="form.strReport"
                          :show-count="true"
                          :multiple="true"
                          :disable-branch-nodes="true"
                          :options="reportTree"
                           placeholder="请选择所属报表"/>
            </el-form-item>
          </el-col>
          <el-col v-if="batchEdit== true" :span="12">
            <el-form-item label="清空所属报表" prop="clearReport">
              <el-switch v-model="form.clearReport"></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="默认值" prop="columnDefault">
              <el-input clearable v-model="form.columnDefault"  placeholder="请输入默认值"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item v-if=" batchEdit== false" label="来源的字段" prop="originalColumnName">
              <el-select style="width: 100%;" filterable clearable v-model="form.originalColumnName"
                         placeholder="请选择来源的字段">
                <el-option
                  v-for="item in  tableColumns"
                  :key="item.columnName"
                  :label="`${item.columnName}【${item.columnChineseName}】`"
                  :value="item.columnName"
                ></el-option>
              </el-select>
              <span slot="label">
                <el-tooltip content="来源的字段标识这个字段是别的字段修改而来，选择会将选择的字段标识为停用状态" placement="top">
                <i class="el-icon-question"></i>
                </el-tooltip>
                来源的字段
              </span>
            </el-form-item>
          </el-col>

          <el-col v-if="batchEdit== true" :span="12">
            <el-form-item label="是否业务主键" prop="businessPrimaryKey">
              <el-select clearable v-model="form.businessPrimaryKey" placeholder="请选择是否业务主键">
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col  v-if="batchEdit== false" :span="12">
            <el-form-item label="是否业务主键" prop="businessPrimaryKey">
              <el-radio-group v-model="form.businessPrimaryKey">
                <el-radio
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="字典编码" prop="codeName">
              <el-select style="width: 100%;" filterable clearable v-model="form.codeName"
                         placeholder="请选择字典编码">
                <el-option
                  v-for="item in tpGlExhibDatadicts"
                  :key="item.classId"
                  :label="`${item.classId}【${item.className}】`"
                  :value="item.classId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="batchEdit== false" :span="12">
            <el-form-item label="版本号" prop="version">
              <el-select :disabled="true" clearable v-model="form.version" placeholder="请选择版本号">
                <el-option
                  v-for="dict in dict.type.report_version"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col v-if="batchEdit== true" :span="12">
            <el-form-item label="内容是否中文" prop="matcherChineseContent">
              <el-select clearable v-model="form.matcherChineseContent" placeholder="请选择内容是否中文">
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="batchEdit== false" :span="12">
            <el-form-item label="内容是否中文" prop="matcherChineseContent">
              <el-radio-group v-model="form.matcherChineseContent">
                <el-radio
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col v-if="batchEdit== true" :span="12">
            <el-form-item label="状态" prop="status">
              <el-select clearable v-model="form.status" placeholder="请选择状态">
                <el-option
                  v-for="dict in dict.type.sys_common_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="batchEdit== false" :span="12">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in dict.type.sys_common_status"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input maxlength="500" clearable v-model="form.remark" type="textarea"
                        placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="isUpdate" :loading="butloading" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog v-if="openDict"  :close-on-click-modal ="false"  :title="titleDict" @ :visible.sync="openDict" width="1000px" append-to-body>
      <datadict :classId="classId" :hisVersion="hisVersion"> </datadict >
      <div slot="footer" class="dialog-footer">
        <el-button @click="openDict = false">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog  v-if="openComparedata" :title="titleComparedata" :close-on-click-modal ="false"  :visible.sync="openComparedata" width="1200px" append-to-body>
      <compare :dataId="dataId" :dataCode="dataCode"> </compare>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openComparedata = false">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog v-if="openDatademandbug"  :title="titleDatademandbug" :close-on-click-modal ="false"  :visible.sync="openDatademandbug" width="1200px" append-to-body>
      <datademandbug :dataId="dataId" :dataCode="dataCode" :hisVersion="hisVersion"> </datademandbug>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openDatademandbug = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listDetail, getDetail, delDetail, addDetail, updateDetail ,init,getInfo,handleUpdateBatch,handleUpdateOrderNum} from "@/api/reportworld/detail";
  import { getTable} from "@/api/reportworld/table";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import { getTableRowStyle } from "@/utils/yss";
  import Sortable from "sortablejs";
  import datadict from "@/views/reportworld/datadict/index";
  import compare from "@/views/reportworld/comparedata/index";
  import datademandbug from "@/views/reportworld/demandbuginfo/datademandbug";

  export default {
    name: "tableDetail",
    components: {
      Treeselect,
      datadict,
      compare,
      datademandbug
    },
    dicts: ['column_type', 'sys_common_status', 'sys_yes_no', 'report_version'],
    data() {
      return {
        butloading:false,
        isUpdate:false,
        // 传递字典编码
        classId: '',
        hisVersion:'',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        searchColl:true,
        showSearchColl:false,
        // 总条数
        total: 0,
        // 报标世界明细信息表格数据
        detailList: [],
        // 弹出层标题
        title: "",
        titleDict: "",
        // 字典弹出层
        open: false,
        openDict:false,
        //所属模块
        modularTree : [],
        // 所属客户
        customerTree: [],
        //所属报表
        reportTree: [],
        // 字典信息
        tpGlExhibDatadicts: [],
        // 字段信息
        tableColumns: [],
        // 批量修改需要隐藏的字段
        batchEdit: false,
        //历史数据
        titleComparedata:'',
        openComparedata:false,
        titleDatademandbug:'',
        openDatademandbug:false,
        dataId:'',
        dataCode:'',
        hisVersionVal:false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 1000,
          columnName: null,
          columnChineseName: null,
          columnType: null,
          primaryKey: null,
          businessPrimaryKey: null,
          codeName: null,
          version: null,
          status: null,
          strModular:[],
          strCustomer:[],
          strReport:[],
          hisVersion:null,
        },
        queryParams2:{},
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          columnName: [
            {required: true, message: "字段名称不能为空", trigger: "blur" }
          ],
          columnChineseName: [
            { required: true, message: "字段中文名称不能为空", trigger: "blur" }
          ],
          columnType: [
            { required: true, message: "字段类型不能为空", trigger: "change" }
          ],
          columnNull: [
            { required: true, message: "是否可为空不能为空", trigger: "change" }
          ],
          primaryKey: [
            { required: true, message: "是否主键不能为空", trigger: "change" }
          ],
          businessPrimaryKey: [
            { required: true, message: "是否业务主键不能为空", trigger: "change" }
          ],
          version: [
            { required: true, message: "版本号不能为空", trigger: "change" }
          ]
        }
      };
    },
    activated() {
      const tableId = this.$route.query.tableId;
      const hisVersion = this.$route.query.hisVersion;
      if(tableId != undefined && tableId){
        this.queryParams.tableId = tableId;
        this.queryParams.hisVersion = hisVersion;
        this.hisVersionVal = false;
        if (this.queryParams.hisVersion) {
          this.hisVersionVal = true;
          this.queryParams2.hisVersionVal = this.queryParams.hisVersion;
        }
        this.init();
        this.getTableInfo();
        this.getList();
      }
    },
    created() {

    },
    methods: {
      getTableInfo(){
        const object = Object.assign({});
        object.id= this.queryParams.tableId;
        object.hisVersion= this.queryParams.hisVersion;
        getTable(JSON.stringify(object)).then(response => {
          this.queryParams2.tableName  = response.data.name;
          this.queryParams2.tableChineseName  = response.data.chineseName;
          if(this.queryParams.hisVersion){
            this.hisVersionVal=true;
            this.queryParams2.hisVersionVal=this.queryParams.hisVersion;
        }
      });
      },
      /** 查询报标世界明细信息列表 */
      getList() {
        this.loading = true;
        listDetail(this.queryParams).then(response => {
          this.detailList = response.rows;
          this.total = response.total;
          this.loading = false;
      });
      },
       init(){
          /* this.$set(this.queryParams, "strModular", null);
           this.$set(this.queryParams, "strCustomer", null);
           this.$set(this.queryParams, "strReport", null);*/
        init(this.queryParams).then(response => {
           this.modularTree=response.modularTree;
           this.customerTree=response.customerTree;
           this.reportTree=response.reportTree;
       });
      },
      getInfo(){
        this.tableColumns=[];
        getInfo(this.queryParams).then(response => {
          this.tableColumns=response.tableColumns;
          this.tpGlExhibDatadicts=response.tpGlExhibDatadicts;
      });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.openDict =false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          tableId: null,
          columnName: null,
          columnChineseName: null,
          columnType: null,
          columnLength: null,
          columnDecimal: null,
          columnNull: null,
          columnDefault: null,
          originalColumnName: null,
          primaryKey: null,
          businessPrimaryKey: null,
          foreignTable: null,
          foreignTableColumn: null,
          codeName: null,
          version: null,
          fileName: null,
          orderNum: null,
          matcherChineseContent: null,
          status: null,
          createTime: null,
          createBy: null,
          updateTime: null,
          updateBy: null,
          remark: null,
          strModular:[],
          strCustomer:[],
          strReport:[],
          hisVersion:null,
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.getList();
      },
      /** 返回按钮操作 */
      handleClose() {
        const obj = { path: "/reportworld/dataInfo/table" };
        this.$tab.closeOpenPage(obj);
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 排序触发事件 */
      handleSortChange(column, prop, order) {
        this.queryParams.orderByColumn = column.prop;
        this.queryParams.isAsc = column.order;
        this.getList();
      },
      // 保存排序
      handleUpdateOrderNum(){
        this.loading = true;
        let arrTableDetail = [];
        for (let index in this.detailList) {
          const tableDetail = Object.assign({});
          tableDetail.id= this.detailList[index].id;
          tableDetail.orderNum =parseInt(index) + 1;
          tableDetail.hisVersion=this.queryParams.hisVersion;
          arrTableDetail.push(tableDetail);
        }
        handleUpdateOrderNum(arrTableDetail).then(response => {
          this.loading = false;
          this.$modal.msgSuccess("保存顺序成功");
        });
        this.getList();
      },
      /** 字典信息 */
      handleDataDictDetail: function(row) {
         this.openDict =true;
         this.classId = row.codeName;
         this.hisVersion=this.queryParams.hisVersion;
         this.titleDict = "字典详细信息";
      },
      comparedata(row){
        this.openComparedata =true;
        this.dataId = row.id;
        this.dataCode = 'REPORT_TABLE_DETAIL_CODE';
        this.titleComparedata = "表字段历史记录信息";
      },
      detailDemandBug(row){
        this.openDatademandbug =true;
        this.dataId = row.id;
        this.dataCode = 'REPORT_TABLE_DETAIL_CODE';
        this.hisVersion=this.queryParams.hisVersion;
        this.titleDatademandbug = "表字段修改记录信息";
      },
      // 更多操作触发
      /*handleCommand(command, row) {
        const id = row.id;
        switch (command) {
          case "comparedata":
            this.handleComparedata(row.id,'REPORT_TABLE_DETAIL_CODE');
            break;
          default:
            break;
        }
      },*/
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加表明细信息";
        this.isUpdate =true;
        this.form.tableId =this.queryParams.tableId;
        this.form.columnType = parseInt(this.dict.type.column_type[0].value);
        this.form.columnNull = parseInt(this.dict.type.sys_yes_no[0].value);
        this.form.primaryKey = parseInt(this.dict.type.sys_yes_no[1].value);
        this.form.businessPrimaryKey = parseInt(this.dict.type.sys_yes_no[1].value);
        this.form.version = this.dict.type.report_version[0].value;
        if(this.queryParams.hisVersion){
          this.form.version =this.queryParams.hisVersion;
        }
        this.form.matcherChineseContent = parseInt(this.dict.type.sys_yes_no[0].value);
        this.form.status = parseInt(this.dict.type.sys_common_status[0].value);
        this.batchEdit=false;
        this.getInfo();
      },
      changeType(value){
        if(1== value || 4== value || 7==value || 8==value || 9==value || 10==value){
          this.$set(this.form, "matcherChineseContent", parseInt(this.dict.type.sys_yes_no[0].value));
        }else{
          this.$set(this.form, "matcherChineseContent", parseInt(this.dict.type.sys_yes_no[1].value));
        }
      },
      /** 修改按钮操作 */
      handleUpdate(row,isUpdate) {
        this.reset();
        const id = row.id || this.ids
        if(isUpdate == false){
          this.queryParams.id=id;
        }else{
          this.queryParams.id=id[0];
        }
        getDetail(this.queryParams).then(response => {
          this.queryParams.id='';
          this.form = response.data;
          this.$set(this.form, "strModular", response.data.strModular);
          this.$set(this.form, "strCustomer", response.data.strCustomer);
          this.$set(this.form, "strReport", response.data.strReport);
          this.open = true;
          this.title = "修改表明细信息";
          this.isUpdate =true;
          if(isUpdate == false){
            this.title = "表明细信息详情";
            this.isUpdate =false;
          }
          this.batchEdit=false;
          this.getInfo();
      });
      },
      /** 复制操作 */
      handleCopy(row) {
        this.handleAdd();
        const id = row.id || this.ids
        this.queryParams.id=id[0];
        getDetail(this.queryParams).then(response => {
          this.queryParams.id='';
          this.form = response.data;
          this.$set(this.form, "strModular", response.data.strModular);
          this.$set(this.form, "strCustomer", response.data.strCustomer);
          this.$set(this.form, "strReport", response.data.strReport);
          this.form.id = null;
          this.form.version = this.dict.type.report_version[0].value;
          if(this.queryParams.hisVersion){
            this.form.version =this.queryParams.hisVersion;
          }
      });
      },
      handleUpdateBatch(row) {
        this.reset();
        this.open = true;
        this.title = "批量修改表明细信息";
        this.rules = {};
        this.batchEdit=true;
        this.isUpdate =true;
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.butloading=true;
            this.form.hisVersion =this.queryParams.hisVersion;
            if (this.form.columnType != 1 && this.form.columnType != 2 && this.form.columnType != 3 &&
              this.form.columnType != 5 && this.form.columnType != 9 && this.form.columnType != 10 && this.batchEdit == false) {
              this.form.columnLength= null;
            }
            if (this.form.columnType != 3 && this.batchEdit == false) {
              this.form.columnDecimal= null;
            }
            if(this.batchEdit==true){
              this.form.idList= this.ids;
              handleUpdateBatch(this.form).then(response => {
              this.open = false;
              this.$modal.msgSuccess("修改成功");
              this.getList();
            }).finally(() => {this.butloading=false});
            }else if (this.form.id != null) {
              updateDetail(this.form).then(response => {
              this.open = false;
              this.$modal.msgSuccess("修改成功");
              this.getList();
            }).finally(() => {this.butloading=false});
            } else {
              addDetail(this.form).then(response => {
              this.open = false;
              this.$modal.msgSuccess("新增成功");
              this.getList();
            }).finally(() => {this.butloading=false});;
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        const hisVersion= this.queryParams.hisVersion;
        this.$modal.confirm('是否确认删除数据项？').then(function() {
          return delDetail(ids,hisVersion);
        }).then(() => {
          this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.queryParams.ids=JSON.stringify(this.ids);
        this.download('reportworld/detail/export', {
          ...this.queryParams
      }, `detail_${new Date().getTime()}.xlsx`)
      },
      tableRowStyle({ row, rowIndex}){
        return getTableRowStyle(row,rowIndex,this.ids);
      },
    rowClick(row, column, event) { //单击行
      this.$refs.tableDetail.toggleRowSelection(row);
    }
    },
    mounted() {
      const el =  document.querySelector('.el-table__body-wrapper tbody')
      const sortable = Sortable.create(el, {
        onEnd: evt => {
        const targetRow = this.detailList.splice(evt.oldIndex, 1)[0];
        this.detailList.splice(evt.newIndex, 0, targetRow);
         for (let index in this.detailList) {
          this.detailList[index].sort = parseInt(index) + 1;
        }
    }
    });
    }
  };
</script>
